package com.kepler.social.web;

public class LinkedList {

    public Node genarate(int level) {
        if (level <= 0) {
            return null;
        }
        Node node = new Node();
        char c = 'A';
        node.setValue(c);
        node.setLeft(child(node, level - 1, 1, 0));
        node.setRight(child(node, level - 1, 1, 1));
        return node;
    }

    /**
     * @param parent
     * @param level
     * @param origin
     * @param dir    0 左 1 右边
     * @return
     */
    public Node child(Node parent, int level, int origin, int dir) {
        if (level == 0) {
            return null;
        }
        Node node = new Node();
        node.setValue((char) ('A' + (origin * 2 - (dir == 0 ? 1 : 0)) % 26));
        node.setParent(parent);
        node.setLeft(child(node, level - 1, origin * 2 + (dir == 0 ? 0 : 1), 0));
        node.setRight(child(node, level - 1, (origin * 2 + (dir == 0 ? 0 : 1)), 1));
        return node;
    }

    public static void main(String[] args) {
        LinkedList list = new LinkedList();
        Node node = list.genarate(6);
    }


}




